Cloud Functions topic

About Cloud Functions

Everything else that can be found on this documentation website is about the frontend of the app: the user interface, the state management, the services that interact with the device's hardware and the Firebase services. While the latter services are also part of the backend, the functions that interact with them are defined within the app itself and are documented here.

Cloud Functions, on the other hand, are functions that run on the server-side of the app. They are written in JavaScript and are hosted on Google's servers. Some are triggered by events that occur in the app, such as a new user signing up, a new event being created, or a user updating their profile. Others are triggered by certain mutations in the Firestore database, such as a new document being created or an existing document being updated. Since these functions are not part of the app itself, they are not documented in the same way as the rest of the app. This page serves as an introduction to the Cloud Functions that are used in the app.

Because Cloud Functions are not part of the app itself, they can be changed without needing to update the app. Nevertheless, some functions need to be called from within the app. AppTeam developers can update and deploy new functions via a procedure described on the Firebase Cloud Functions page of the wiki.

The Functions

What follows is a list of the Cloud Functions that are used in the app, grouped by category.

Admin functions

  • addAdminRole: Adds the admin role to a user. Only admins can call this function.
  • removeAdminRole: Removes the admin role from a user. Only admins can call this function.
  • renameUser: Renames a user, typically because users may not have entered there names correctly. Only admins can call this function.

User fetching functions

  • retrieveUserById: Retrieves a user by their user ID. Currently not used in the app.
  • retrieveUserlist: Retrieves a list of all users. This is called when the app is started. While a costly operation, it was deemed more efficient than fetching users one by one when needed. This may be changed in the future.

User management functions

  • customClaimsSet: Sets the custom claims of a user when they are created. This is done to prevent users from using the app before they have been approved by an admin.
  • enableUserClaims: Enables a user when they are approved by an admin. This is done by updating the user's custom claims.
  • deleteUser: Deletes a user from the app. This is done when a user requests to be deleted from the settings page or when an admin deletes a user from their profile page.

Notification functions

  • newEventNotification: Sends a notification to users when a new event is created. Only users who have the 'new event notifications' setting enabled will receive this notification. Clicking on the notification will take the user to the event details page. Additionally, this function adds the event to the Firestore document that is used by the notification inbox accessible from the app's home screen.
  • newPostNotification: Sends a notification to users when a new post is created. Only users who have the 'new post notifications' setting enabled will receive this notification. Clicking on the notification will take the user to the post details page. Additionally, this function adds the post to the Firestore document that is used by the notification inbox accessible from the app's home screen.
  • taggingNotification: Sends a notification to users when they are tagged in a comment. Only users who have the 'tagging notifications' setting enabled will receive this notification. Clicking on the notification will take the user to the post or event where they were tagged.
  • userPendingNotification: Sends a notification to admins when a new user signs up. This is done to notify admins that a new user is waiting to be approved.
  • postEdditedNotification: When a post is edited, this function is called to edit the post's entry in the notification inbox document. This is done to ensure that the notification inbox is up to date.
  • activityEditedNotification: When an activity is edited, this function is called to edit the activity's entry in the notification inbox document. This is done to ensure that the notification inbox is up to date.

Database cleanup functions

  • commentSectionCleanup: Deletes the Firestore document containing the comments of a post whenever a post is deleted. This is done to prevent orphaned documents from taking up space in the database.
  • activityBannerCleanup: Deletes the banner image of an activity whenever the activity is deleted. This is done to prevent orphaned images from taking up space in the storage bucket.
  • userAvatarCleanup: Deletes the avatar image of a user whenever the user is deleted. This is done to prevent orphaned images from taking up space in the storage bucket. Both the large image and the thumbnail are deleted.
  • participantsCleanup: Deletes the Firestore document containing the participants of an event whenever the event is deleted. This is done to prevent orphaned documents from taking up space in the database.

Firestore document creation functions

  • createParticipantsDocument: Creates a Firestore document containing the participants of an event whenever a new event is created.
  • createCommentDocument: Creates a Firestore document containing the comments of a post whenever a new post is created.
  • createEventCommentDocument: Creates a Firestore document containing the comments of an event whenever a new event is created.

CORS proxy functions

CORS stands for Cross-Origin Resource Sharing. It is a security feature that prevents a browser webpage from making requests to a different domain than the one that served the webpage. This is a problem when the app needs to fetch images from a different domain than the one that serves the app. The app is served from app.aegee-leiden.nl. However, it also shows events from AEGEE-Europe, which come from my.aegee.eu. Additionally, users can attach images to posts that may be hosted on different domains. To prevent the app from being unable to fetch these images, a CORS proxy is used: a cloud function that fetches the image from the other domain and serves it to the app. The following functions are used for this purpose:

  • corsImage: Fetches an image from a different domain and serves it to the app. Used for example for AEGEE-Europe event banners and images attached to posts.
  • corsJson: Fetches a JSON object from a different domain and serves it to the app. Used for example for fetching the AEGEE-Europe event list.

Photos

  • newEventPhotosFolderCreation: Whenever an activity is created, this function checks if the 'create photo album' setting is enabled. If it is, a new folder is created in the Google Drive folder of the year in which the activity takes place, both the Public folder and the Private folder. The year folders need to be created manually for now. The creation of these folders is made possible by a service account that has access to the Intranet Drive.

Google Calendar functions

  • createCalendarEvent: Creates a new event in the Google Calendar of the AEGEE-Leiden whenever a new event is created. The event contains the title, description, start and end time, and location of the event. The event is created by a service account that has access to the AEGEE-Leiden Google Calendar.
  • updateCalendarEvent: Updates an existing event in the Google Calendar of the AEGEE-Leiden whenever an event is updated.
  • deleteCalendarEvent: Deletes an existing event in the Google Calendar of the AEGEE-Leiden whenever an event is deleted.

Meta tag functions

Meta tags are used to provide information about a webpage to search engines and social media platforms. They are typically used to provide a title, description, and image for a webpage. For the AEGEE app, this is used to create event previews when sharing an event on social media, including WhatsApp.

  • dynamicMetaTagsUpdate: Updates the meta tags of the app's index.html file whenever an event page is visited by a bot (such as a search engine or a social media platform). The meta tags are updated to reflect the title, description, and image of the event that is being shared. This is done by fetching the event data from Firestore and updating the meta tags accordingly.

User profile updates

Changes to a user's profile are done through various ways. The Admin section already mentioned the renameUser function. The AuthUpdateFunctions contains functions for updating a user's email address, password, and profile picture. However, there are some cloud functions for other profile updates:

  • updatePhoneNumber: Updates the phone number of a user whenever the user updates their profile.
  • updateBirthday: Updates the birthday of a user whenever the user updates their profile.

Classes

CloudFunctionService Services Cloud Functions
A service for interacting with Firebase Functions.